from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models

# Create your models here.
from db.base_model import BaseModel


class CategoryFirst(BaseModel):
    """一级分类模型"""
    name = models.CharField(max_length=100, verbose_name='分类名')

    def __str__(self):
        return self.name

    class Meta:
        db_table = '一级分类表'
        verbose_name = '一级分类管理'
        verbose_name_plural = verbose_name


class CategorySecond(BaseModel):
    """二级分类模型"""
    name = models.CharField(max_length=100, verbose_name='分类名')

    def __str__(self):
        return self.name

    class Meta:
        db_table = '二级分类表'
        verbose_name = '二级分类管理'
        verbose_name_plural = verbose_name


class Label(BaseModel):
    """标签模型"""
    name = models.CharField(max_length=100, verbose_name='标签名')

    def __str__(self):
        return self.name

    class Meta:
        db_table = '标签表'
        verbose_name = '标签管理'
        verbose_name_plural = verbose_name


class Blog(BaseModel):
    """博文模型"""
    choices = ((0, '否'), (1, '是'))
    title = models.CharField(max_length=100, verbose_name='博文标题')
    logo = models.ImageField(upload_to='blog/%Y/%m', null=True, blank=True, verbose_name='博文logo')
    brief = models.CharField(max_length=200, null=True, blank=True, verbose_name='博文简介')
    content = RichTextUploadingField(null=True, blank=True, verbose_name='博文正文')
    hits = models.IntegerField(null=True, blank=True,default=0,verbose_name='点击数')
    source = models.CharField(max_length=200, null=True, blank=True, verbose_name='博文来源')
    integral=models.IntegerField(null=True, blank=True,default=0,verbose_name='所需积分')
    is_integral=models.IntegerField(choices=choices,default=0,verbose_name='是否需要积分')
    label =models.ManyToManyField(to=Label,null=True, blank=True,verbose_name='标签')
    category1=models.ForeignKey(to=CategoryFirst,null=True, blank=True,verbose_name='一级分类')
    category2=models.ForeignKey(to=CategorySecond,null=True, blank=True,verbose_name='二级分类')
    is_show = models.IntegerField(choices=choices, default=1, verbose_name='是否展示')

    def __str__(self):
        return self.title

    class Meta:
        db_table='博文表'
        verbose_name='博文管理'
        verbose_name_plural=verbose_name